package me.jiatao.usermanage.service.impl;

import me.jiatao.usermanage.mapper.UserMapper;
import me.jiatao.usermanage.pojo.User;
import me.jiatao.usermanage.service.UserService;
import me.jiatao.usermanage.view.DataGridPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public DataGridPage getPage(Integer pageNum, Integer pageSize) {
        List<User> userList = userMapper.select(null);

        DataGridPage gridPage = new DataGridPage();
        gridPage.setTotal(userList.size());
        gridPage.setRows(userList);

        return gridPage;
    }

    @Override
    public int saveUser(User user) {
        return userMapper.insertSelective(user);
    }

    @Override
    public User getUserByID(Long ids) {
        return userMapper.selectByPrimaryKey(ids);
    }

    @Override
    public int modifyUser(User user) {
//        userMapper.updateByPrimaryKeySelective(user);
//        int x = 100 / 0;
        return userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public int deleteUser(Long userID) {
        return userMapper.deleteByPrimaryKey(userID);
    }
}
